﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace FixedEyes3
{
    // класс для сравнения пикселов двух изображений
    public class ImageComparer
    {
        // в конструкторе создаем черный цвет, близкий к цвету зрачка
        public ImageComparer(byte R, byte B, byte G)
        {
            color.R = R;
            color.G = G;
            color.B = B;
        }

        public void Compare(WriteableBitmap bitmap)
        {
            leftBottomCount = 0;
            leftTopCount = 0;
            rightTopCount = 0;
            rightBottomCount = 0;

            for (int y = startY; y < endY; y++)
            {
                for (int x = startX; x < endX; x++)
                {
                    if (IsLike(bitmap.GetPixel(x, y), color))
                    {
                        bitmap.SetPixel(x, y, Colors.Red);

                        if (x < centreX && y < centreY)
                            leftBottomCount++;
                        else if (x < centreX && y > centreY)
                            leftTopCount++;
                        else if (x > centreX && y > centreY)
                            rightTopCount++;
                        else if (x > centreX && y < centreY)
                            rightBottomCount++;
                    }
                }
            }
        }

        bool IsLike(Color firstColor, Color secondColor)
        {
            return (Math.Abs(firstColor.R - secondColor.R) < 40 && Math.Abs(firstColor.G - secondColor.G) < 40
                && Math.Abs(firstColor.B - secondColor.B) < 40);
        }

        Color color;
        // количество пикселов по сторонам
        int leftBottomCount = 0;
        int leftTopCount = 0;
        int rightTopCount = 0;
        int rightBottomCount = 0;
        //int startY = 0;
        //int endY = 480;
        //int startX = 0;
        //int endX = 640;
        int startY = 250;
        int endY = 280;
        int startX = 450;
        int endX = 480;
        int centreX = 465;
        int centreY = 265;

        public int LeftBottomCount
        {
            get { return leftBottomCount; }
        }

        public int LeftTopCount
        {
            get { return leftTopCount; }
        }

        public int RightTopCount
        {
            get { return rightTopCount; }
        }

        public int RightBottomCount
        {
            get { return rightBottomCount; }
        }
    }
}